﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Models
{
    public class FormSetting:IDbServices<bool,int,TblFormSetting>
    {
        BookingDB db = new BookingDB();

        public bool AddData(TblFormSetting e)
        {
            try
            {
                db.TblFormSettings.Add(e);
                db.SaveChanges();
                return true;
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
                return false;
            }
        }

        public bool UpdateData(TblFormSetting e)
        {
            try
            {
                db.Entry(e).State = EntityState.Modified;
                db.SaveChanges();
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }

        public bool DeleteData(int key)
        {
            TblFormSetting objType = new TblFormSetting();
            objType = db.TblFormSettings.Find(key);
            try
            {
                db.TblFormSettings.Remove(objType);
                db.SaveChanges();
                return true;

            }
            catch (Exception)
            {

                return false;
            }

        }

        public TblFormSetting GetDataByKey(int k)
        {
            try
            {
                return db.TblFormSettings.Find(k);
            }
            catch (Exception)
            {

                return null;
            }
        }

        public List<TblFormSetting> GetAll()
        {
            try
            {
                return db.TblFormSettings.ToList<TblFormSetting>();
            }
            catch (Exception)
            {

                return null;
            }
        }
    
    }
}
